package builder.standard;

import lombok.Data;

//产品类：套餐
@Data
class Meal {
    private String burger;

    private String fries;

    private String drink;
}

//抽象建造者
abstract class MealBuilder {
    protected Meal meal = new Meal();

    public abstract void buildBurger();

    public abstract void buildFries();

    public abstract void buildDrink();

    public Meal getMeal() {
        return meal;
    }
}

//抽象建造者：牛肉汉堡
class BeefBurgerMealBuilder extends MealBuilder {

    @Override
    public void buildBurger() {
        meal.setBurger("牛肉汉堡");
    }

    @Override
    public void buildFries() {
        meal.setFries("大份薯条");
    }

    @Override
    public void buildDrink() {
        meal.setDrink("中杯可乐");
    }
}

//抽象建造者：鸡肉汉堡
class ChickenMealBuilder extends MealBuilder {

    @Override
    public void buildBurger() {
        meal.setBurger("鸡肉汉堡");
    }

    @Override
    public void buildFries() {
        meal.setFries("中份薯条");
    }

    @Override
    public void buildDrink() {
        meal.setDrink("大杯果汁");
    }
}

//指导者
class MealDirector {
    private MealBuilder mealBuilder;

    public void setMealBuilder(MealBuilder mealBuilder) {
        this.mealBuilder = mealBuilder;
    }

    public void constructMeal() {
        mealBuilder.buildBurger();
        mealBuilder.buildFries();
        mealBuilder.buildDrink();
    }

    public Meal getMeal() {
        return mealBuilder.getMeal();
    }
}

public class Consumer {
    public static void main(String[] args) {
        //创建指导者
        MealDirector mealDirector = new MealDirector();

        //执导建造牛肉套餐
        mealDirector.setMealBuilder(new BeefBurgerMealBuilder());
        mealDirector.constructMeal();
        Meal meal = mealDirector.getMeal();
        System.out.println("牛肉套餐：" + meal.toString());

        //鸡肉套餐
        mealDirector.setMealBuilder(new ChickenMealBuilder());
        mealDirector.constructMeal();
        Meal meal2 = mealDirector.getMeal();
        System.out.println("鸡肉套餐：" + meal2.toString());
    }
}